﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace ArrayListExample
{
    /// <summary>
    /// Purpose: Sample Code for ArrayList with Structures.
    /// Date: 20-Apr-2010
    /// Author: Abhijit Shrikhande
    /// Note: This still doesn't look like it produces a dynamic array.
    /// </summary>

    class Program
    {

        public struct MyStruct
        {
            public int t1;
            public string s1;
        }
        static void Main(string[] args)
        {
            ArrayList x = new ArrayList();
            object[] myarray = new object[2];
            MyStruct y = new MyStruct();
            
            y.t1 = 100;
            y.s1 = "Joe";
            myarray[0] = y;
            x.Add(y);

            y.t1 = 101;
            y.s1 = "Tony";
            myarray[1] = y;
            x.Add(y);

            /// We can use the sort property to sort the numbers.
            //x.Sort();
            Example(x);
            testSnippet();
        }

        private static void Example(ArrayList x)
        {
            checked
            {
                foreach (MyStruct item in x)
                {

                Console.WriteLine("{0}:{1}", item.s1, item.t1);

                }
            }
        }
        private static void testSnippet() 
        {
            /// <summary>
            /// Purpose: Sample Code for Dictionary Object
            /// Date: 21-Apr-2010
            /// Author: Abhijit Shrikhande
            /// Note: This can produce a key value pair and can grow and shrink.
            /// </summary>

            Dictionary<string, string> stateCaps = new Dictionary<string, string>();
            stateCaps.Add("NM", "Santa Fe");
            stateCaps.Add("PA", "Harrisburg");
            stateCaps.Add("NY", "Albany");
            Console.WriteLine("********************************");
            Console.WriteLine("START PRINT STATE CAPITOLS");
            Console.WriteLine("*********************************");
            foreach (var x in stateCaps)
            {
                Console.WriteLine(x.Key + " - " + x.Value);
            }
            Console.WriteLine("**********************");
            Console.WriteLine("END PRINT CAPITOLS");
            Console.WriteLine("**********************");
        }
    }
}
